var tableName = "detailItemBody";
var typeid = "typeid";
var typeids="";


function loadSidebar(sidebar){
	if(sidebar != null && sidebar.length > 0){
		for(var i=0;i<sidebar.length;i++){
			if(sidebar[i].innerHTML != ""){
				var htmlStr = $.trim(sidebar[i].innerHTML).split(",");
				if(htmlStr[0] != null && htmlStr[0] != ""){
					tableName = htmlStr[0];
				}
				if(htmlStr[1] != null && htmlStr[1] != ""){
					typeid = htmlStr[1];
					typeids+=typeid+",";
				}
				
			}
			sidebar[i].innerHTML = "<table  class='mytabstyle center_align' style='border-top:0px;'" +
			"<tr><td align='center' class='greybk'>" +
			"<span class='My_btn_small greenbtn' id='btnAdd' name='btnAdd' onclick=\"addOrderRow('"+tableName+"','"+typeid+"','add')\" >增加行</span>" +
			"<span class='My_btn_small redbtn' id='btnDelete' name='btnDelete' onclick=\"addOrderRow('"+tableName+"','"+typeid+"','delete')\" >删除行</span>" +
			"</td></tr>" +
			"</table>";
		}
		if(typeids.length > 0){
			typeids = typeids.substring(0,typeids.length-1);
		}
	}
}

var sidebar = document.getElementsByName('sidebar');

loadSidebar(sidebar);

function MaxLen(obj,len){
	var strlen = 0;
	for(var i=0;i<obj.value.length;i++){
		if(obj.value.charCodeAt(i)>255){
			strlen += 3;
		}else{
			strlen ++;
		}
		if(strlen>len){
			obj.value = obj.value.substring(0,i);
		}
	}
}